﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DotNetNuke.Common.Utilities;
using Christoc.Modules.CouponsDiscounts.Data;

namespace Christoc.Modules.CouponsDiscounts.Components.Controllers
{
    public class DiscountController
    {
        public static Discount GetDiscount(int DiscountID)
        {
            return CBO.FillObject<Discount>(DataProvider.Instance().GetDiscount(DiscountID));
        }

        public static List<Discount> GetDiscounts(int DiscountID)
        {
            return CBO.FillCollection<Discount>(DataProvider.Instance().GetDiscounts());
        }

        public static Discount GetDiscountProduct(int productId)
        {
            return CBO.FillCollection<Discount>(DataProvider.Instance().GetDiscountProduct(productId)).FirstOrDefault<Discount>();
        }

        public static int SaveDiscount(Discount discount)
        {
            //if (discount.DiscountID < 0)
            {
                discount.DiscountID = DataProvider.Instance().AddDiscount(discount);
            }
            //else
            { 
                //Add code to update existing discount
            }

            return discount.DiscountID;
        }

        public static void DeleteDiscount(int discountID)
        {
            DataProvider.Instance().DeleteDiscount(discountID);
        }

        public static void SaveProductDiscount(int discountId, int productID)
        {
            DataProvider.Instance().AddProductDiscount(discountId, productID);
        }
    }
}